package org.dh2580.netty.demo.bio;

import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 伪异步IO
 * <p>
 * 伪异步IO当出现，网络阻塞或者发送方发送数据缓慢时，消费方将出现无限等待状态，直到有数据可用或者抛出异常。
 * 在等待状态时，会一直占用着线程，导致后续的请求进来进入队列，如果队列打满，则会出现入队失败情况，服务端不可用
 * </p>
 *
 * @Author: hao.deng
 * @Date: 2019/3/20-上午11:21
 */
public class PoolTimeServer {
    public static void main(String[] args) throws Exception {
        ServerSocket serverSocket = new ServerSocket(8080);

        ExecutorService executor = Executors.newFixedThreadPool(10);

        while (true) {
            Socket socket = serverSocket.accept();
            executor.execute(new TimeServer.TimeServerHandler(socket));
        }
    }
}
